package cn.com.vastbase.hibernate.sample.springmvc.business.service.impl;

import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAttribute;
import org.springframework.transaction.interceptor.TransactionAttributeSource;
import org.springframework.transaction.support.TransactionSynchronizationManager;

import java.lang.reflect.Method;

@Service
public class SomeThingCommon {


    @Autowired
    private TransactionAttributeSource transactionAttributeSource;


    private String doSomeThings0(String id) {
        String currentTransactionName = TransactionSynchronizationManager.getCurrentTransactionName();
        System.out.println("doSomeThings0:" + currentTransactionName);
        boolean readOnly = TransactionSynchronizationManager.isCurrentTransactionReadOnly();
        System.out.println("Current transaction is read-only: " + readOnly);
        return doSomeThings1(id);
    }

    public static String doSomeThings1(String id) {
        String currentTransactionName = TransactionSynchronizationManager.getCurrentTransactionName();
        System.out.println("doSomeThings1:" + currentTransactionName);

        return id + " is " + currentTransactionName;
    }

    public String doSomeThings(String id) throws NoSuchMethodException {
        String currentTransactionName = TransactionSynchronizationManager.getCurrentTransactionName();
        System.out.println("doSomeThings:" + currentTransactionName);
        return doSomeThings0(id);
    }

}
